﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpertMIS.Brokers;
using ExpertMIS.Entities;

namespace ExpertMIS.Admin.UserControl
{
    public partial class SiteMessageForm : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public bool SendMessage()
        {
            try
            {
                // 获取用户列表
                if (string.IsNullOrEmpty(hfSelectedUser.Value))
                {
                    return false;
                }

                ADMSiteMessageBroker broker = new ADMSiteMessageBroker();

                string[] userList = hfSelectedUser.Value.Split(',');
                foreach (string userID in userList)
                {
                    ADMSiteMessageEntity entity = new ADMSiteMessageEntity();
                    entity.Title = txTitle.Text;
                    entity.Content = txContent.Text;
                    entity.ReceiveUser = userID;
                    entity.SendTime = DateTime.Now;
                    entity.IsRead = false;
                    broker.SaveEntity(entity, null);
                }

                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}